<?php

namespace Admin\Controller;
use Think\Controller;

class UserController extends CommonController {
    public function index(){
		$this->display(); // 输出模板

    }

    
    public function ajaxpage(){
    	$User = M('user'); 
		$count = $User->count();
		$Page = new \Think\Ajaxpage($count,2);
		$Page->setConfig('prev','上一页');
		$Page->setConfig('next','下一页');
		$Page->setConfig('first','首页');
		$Page->setConfig('last','尾页');
		$list = $User->order('id')->limit($Page->firstRow.','.$Page->listRows)->select();
		$show = $Page->show();// 分页显示输出
		$arr=array(
			"list"=>$list,
			"show"=>$show
		);
		$this->ajaxReturn($arr);
    }
    
    //添加账号
    public function add(){
    	if(IS_POST){
    		 $_POST['password']=md5($_POST['password']);
    	     $user = M('User');
    	     $where_name['name']=$_POST['name'];
    	     $where_tel['tel']=$_POST['tel'];
    	     $where_email['email']=$_POST['email'];
    	     if($user->where($where_name)->find()){
    	     	$this->error("用户名已存在，请别的用户名！","",5);
    	     }else if($user->where($where_tel)->find()){
    	     	$this->error("手机号已被使用，请输入别的手机号！","",5);
    	     }else if($user->where($where_email)->find()){
    	     	$this->error("邮箱地址已被使用","",5);
    	     }else{
    	         if($user->create()){
	             	if($user->add()){
	             		$this->success("添加成功");
	             	}else{
	             		$this->error("添加失败！错误代码:001");
	             	}
	             }else{
	             	$this->error("添加失败！错误代码:002");
	             }
    	     }
    	}else{
    		$this->error("非法请求！");
    	}
	}

}